﻿using Fast;
using Fast.Validation;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 异常服务扩展类
    /// </summary>
    [SkipScan]
    public static class FastExceptionServiceCollectionExtensions
    {
        /// <summary>
        /// 添加异常服务扩展服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        internal static IServiceCollection AddFastException(this IServiceCollection services)
        {
            // 是否抑制自带的模型验证
            services.Configure<ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true);
            // 添加模型验证过滤器
            services.AddMvcFilter<FastValidationFilter>();
            // 添加异常过滤器
            services.AddMvcFilter<FastExceptionFilter>();

            return services;
        }
    }
}
